import pandas as pd
import numpy as np


# create with DatetimeIndex
dates = pd.date_range('20130101', periods=6)
df = pd.DataFrame(np.random.randn(6,4), index=dates, columns=list('ABCD'))

# Boolean Indexing
# Using a single column’s values to select data.
df[df.A > 0]
# A where operation for getting.
df[df > 0]
# Using the isin() method for filtering:
df2 = df.copy()
df2['E'] = ['one', 'one','two','three','four','three']
#print(df2)
result = df2[df2['E'].isin(['two','four'])]
#print(result)

# Setting
s1 = pd.Series([1,2,3,4,5,6], index=pd.date_range('20130102', periods=6))
df['F'] = s1
df.at[dates[0],'F'] = 0
df.iat[0,1] = 0
#print(df)
df2 = df.copy()
df2[df2 > 0] = -df2
#print(df2)
# Reindexing allows you to change/add/delete the index on a specified axis. This returns a copy of the data.
df1 = df.reindex(index=dates[0:4], columns=list(df.columns) + ['E'])
df1.loc[dates[0]:dates[1],'E'] = 1
print(df1)
# To drop any rows that have missing data.
df_tmp = df1.dropna(how='any')
print(df_tmp)
# Filling missing data
df1.fillna(value=5)
# To get the boolean mask where values are nan
pd.isnull(df1)